<%
/**
 * second wizard page / tab
 *
 * @author	Jeroen Wesbeek <work@osx.eu>
 * @package AjaxFlow
 */
%>
<script type="text/javascript" >
function addRendita(tip,tot){
	
	    	var next = parseInt($("#count_rendita").val());     
	        var addto = "#new_row_rendita_" + (next);
	        var divRow=$('<div class="row" id="new_row_rendita_' + (next+1)+'"></div>');
	        var divColBtn=$('<div class="col-sm-1"></div>');
	        var removeButton = $('<button type="button" class="btn btn-danger btn-md " id="remove_rendita_' + (next+1) + '" >'+
	    	        				'<i class="glyphicon glyphicon-trash"></i></button>	');
	        removeButton.click(function(e){
               e.preventDefault();
               var fieldNum = this.id.charAt(this.id.length-1);
               var fieldID = "#new_row_rendita_" + fieldNum;
               $(fieldID).remove();
               var next = parseInt($("#count_rendita").val());
               next = (next -1);
               $("#count_rendita").val(next);  
           }); 
	        divColBtn.append(removeButton)
	        divRow.append(divColBtn);
	        var rendValue=$('<div class="col-sm-5 "><div class="form-group"><div class="input-group"><span class="input-group-addon">'+
	    	        		'<i class="fa fa-info fa-lg fa-fw"></i></span>'+
	    	        			'<input class="form-control input-md rndInput" placeholder="Tipologia" type="text" name="rendita" id="rendita" value="'+((tip!=null)?tip:'')+'">'+
	    	        		'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
	    	        		'<span class="input-group-addon"><i class="fa fa-eur fa-lg fa-fw"></i></span>'+
	    	        			'<input class="form-control input-md rndTotInput currency" placeholder="Tot. Euro Annuo" type="text" name="rendita_importo" id="rendita_importo" value="'+((tot!=null)?tot:'')+'">'+
	    	        		'</div></div></div></div>');
	        divRow.append(rendValue);
	        next = next + 1;
	        $(addto).after(divRow);
	        $("#count_rendita").val(next);	
	        currencyFormatter(); 
	 }

    


	function remappingBean(){
			 $("#add_more_rendita").click(function(e){
				 e.preventDefault();
				addRendita('','');
					
			  });	
	    
	    	    <g:if test="${customer?.renditaTitDep}">
	    		    <g:each in="${customer.renditaTitDep}" var="item">
	    		    	<g:if test="${item.tipologyRendita}">
	    		    		addRendita('${item.tipologyRendita}','${item.totEuroRendita.toString()}');	
	    		    	 </g:if>	
	    			</g:each>
	    	    </g:if>	    
	    	    
	    <g:if test="${customer?.job?.jobType?.id}">
		    <g:if test="${customer?.job?.jobType?.id < 4 && customer?.job?.jobType?.id > -1}">														
				${remoteFunction(controller:'Interview',action:'renderCassIntJob',update:'render_jobType',,onSuccess:'readOnly();toUpperCase();currencyFormatter();',
					params:[jobId: customer?.job?.jobType?.id,redditoNettoAnnuo:customer?.job?.redditoNettoAnnuo,mensilita:customer?.job?.mensilita,
					contractType:customer?.job?.contractType,impiegoType:customer?.job?.impiegoType]) }
			</g:if>
			<g:else>
		    	<g:if test="${customer?.job?.jobType?.id > 4}">	
					${remoteFunction(controller:'Interview',action:'renderCassIntJob',update:'render_jobType',onSuccess:'readOnly();toUpperCase();currencyFormatter();',
						params:[attivoLastYear:customer?.job?.attivoLastYear,ricaviLordiLastYear:customer?.job?.ricaviLordiLastYear,debitiLastYear:customer?.job?.debitiLastYear,
								attivoSecondLastYear:customer?.job?.attivoSecondLastYear,ricaviLordiSecondLastYear:customer?.job?.ricaviLordiSecondLastYear,debitiSecondLastYear:customer?.job?.debitiSecondLastYear,
								attivoThirdLastYear:customer?.job?.attivoThirdLastYear,ricaviLordiThirdLastYear:customer?.job?.ricaviLordiThirdLastYear,debitiThirdLastYear:customer?.job?.debitiThirdLastYear,
							activityType:customer?.job?.activityType]) }
				</g:if>
			</g:else>
	    </g:if>    
	   
	 }

</script>
<af:page>
<div class="alert alert-danger fade in" id="validity_label"></div>
<g:if test="${interview}">
<div class="col-sm-3 col-md-offset-9">
	<h3>Intervista : <exdutility:number_interview value="${interview?.id }"/></h3>
</div>
</g:if>
<h3>Attivita Lavorativa</h3>
<div class="row">
	<div class="col-sm-5 col-md-offset-1">
		<div class="form-group">
			<div class="input-group">
				<span class="input-group-addon"><i class="fa fa-briefcase fa-lg fa-fw"></i></span>
				<g:select class="form-control" id="jobSelect" name="value" from="${com.macrosolution.exdebito.JobType?.list()}" 
					value="${customer?.job?.jobType?.id}" optionKey="id" optionValue="value" noSelection="['-1':'- Seleziona il lavoro -']"
					onChange="${remoteFunction(controller:'Interview',action:'renderCassIntJob',update:'render_jobType',params:'\'jobId=\'+this.value',onComplete:'currencyFormatter();') }"/>
			</div>
		</div>
	</div>
</div>

<div id="render_jobType">
</div>

<%--//ALTRA RENDITA--%>
<br/><br/>

<h3>Inserire altra Rendita, Titolo, Deposito, Etc.&nbsp;&nbsp;&nbsp;
	<a class="collapsed">  
		<button type="button" class="btn btn-info btn-md" id="add_more_rendita" style="margin-bottom:12px">
			<i class="fa fa-plus"></i>
		</button>
		
	</a>
</h3>
<input type="hidden" name="count_rendita" id="count_rendita" value="0"/>
<div id="new_row_rendita_0"></div>

</br></br></br>
<div style="border-top: 2px solid #006DBA; padding-top: 2px;"></div>
</af:page>
